#include <unistd.h>
#include <iostream>
#include <event_cpp/loop.h>
#include <event_cpp/fd_event.h>

using namespace std;
using namespace lumi;
using namespace lumi::event_cpp;

void FdCallback(short event)
{
    char input_buff[200];
    int rsize = read(STDIN_FILENO, input_buff, sizeof(input_buff));
    input_buff[rsize - 1] = '\0';
    cout << "INPUT is [" << input_buff << "]" << endl;
}

int main()
{
    LoopSptr sp_loop = Loop::New(Loop::kLibeventType);

    FdEventSptr sp_fd = sp_loop->newFdEvent();
    sp_fd->initialize(STDIN_FILENO, FdEvent::kReadEvent, Event::kPersistMode);
    sp_fd->setCallback(MakeFunction(FdCallback, _1));
    sp_fd->enable();

    sp_loop->runLoop(Loop::kLoopForever);
    return 0;
}
